﻿Imports System.Globalization

Public Class GeneralFunctions
    Shared Function ToFileSizeString(size As Long) As String
        If size < 1000 Then
            Return [String].Format("{0} bytes", size)
        End If
        If size < 1000000 Then
            Return [String].Format("{0:F1} KB", (size / 1000))
        End If
        If size < 1000000000 Then
            Return [String].Format("{0:F1} MB", (size / 1000000))
        End If
        If size < 1000000000000L Then
            Return [String].Format("{0:F1} GB", (size / 1000000000))
        End If
        If size < 1000000000000000L Then
            Return [String].Format("{0:F1} TB", (size / 1000000000000L))
        End If
        Return size.ToString(CultureInfo.InvariantCulture)
    End Function
End Class
